package io.renren.modules.evaluate.controller;

import io.renren.common.utils.R;
import io.renren.modules.evaluate.dao.NormMesDao;
import io.renren.modules.evaluate.dao.UpLoadMapper;
import io.renren.modules.evaluate.entity.Judge;
import io.renren.modules.evaluate.entity.M;
import io.renren.modules.evaluate.service.IndexService;
import io.renren.modules.sys.controller.SysLoginController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class IndexController {
    @Autowired
    SysLoginController sysLoginController;
    @Autowired
    NormMesDao normMesDao;
    @Autowired
    UpLoadMapper upLoadMapper;
    @Autowired
    IndexService indexService;

    @ApiOperation("啥玩楞")
    @GetMapping("index/find")
    public List<Judge> findbyid(){
        Long userid = sysLoginController.get();

        List<Judge> list = normMesDao.GetJudgeByUserId(userid);
        return list;

    }

    @ResponseBody
    @ApiOperation("根据name动态查询表")
    @GetMapping("index/findByTableName")
    public List<Object> getByTableName(String name){
       List<Object> l2 = new ArrayList<>();
/*       List<Object> l3 = new ArrayList<>();*/
        List<HashMap<String,Object>> l = upLoadMapper.getByTableName(name);

            for (Map.Entry<String, Object> entry : l.get(1).entrySet()) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("pinyin",entry.getKey());
                map.put("name",indexService.findByname(entry.getKey()));
                /*l2.add(map);*/
               l2.add(map);
            }
           l2.add(l);

        return l2;
    }





}
